<template>
  <aside class="sidebar">
    <!-- 快捷访问 -->
    <div class="sidebar-section">
      <h3 class="section-title">快捷访问</h3>
      <ul class="sidebar-menu">
        <li class="menu-item" :class="{ active: activeMenu === 'myFiles' }" @click="handleMenuItemClick('myFiles')">
          <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
            <path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"></path>
          </svg>
          <span>我的文件</span>
        </li>
        <li class="menu-item" :class="{ active: activeMenu === 'upload' }" @click="handleMenuItemClick('upload')">
          <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
            <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path>
            <polyline points="7 10 12 15 17 10"></polyline>
            <line x1="12" y1="15" x2="12" y2="3"></line>
          </svg>
          <span>上传文件</span>
        </li>
        <li class="menu-item" :class="{ active: activeMenu === 'downloaded' }" @click="handleMenuItemClick('downloaded')">
          <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
            <path d="M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3"></path>
          </svg>
          <span>已下载</span>
        </li>
        <li class="menu-item" :class="{ active: activeMenu === 'recent' }" @click="handleMenuItemClick('recent')">
          <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
            <path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"></path>
          </svg>
          <span>最近文件</span>
        </li>
        <li class="menu-item" :class="{ active: activeMenu === 'shared' }" @click="handleMenuItemClick('shared')">
          <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
            <path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"></path>
            <circle cx="9" cy="7" r="4"></circle>
            <path d="M22 21v-2a4 4 0 0 0-3-3.87"></path>
            <path d="M16 3.13a4 4 0 0 1 0 7.75"></path>
          </svg>
          <span>共享文件</span>
        </li>
      </ul>
    </div>
    
    <!-- 文件分类 -->
    <div class="sidebar-section">
      <h3 class="section-title">文件分类</h3>
      <ul class="sidebar-menu">
        <li class="menu-item" :class="{ active: activeCategory === 'docs' }" @click="handleCategoryClick('docs')">
          <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
            <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path>
            <polyline points="14 2 14 8 20 8"></polyline>
            <line x1="16" y1="13" x2="8" y2="13"></line>
            <line x1="16" y1="17" x2="8" y2="17"></line>
            <polyline points="10 9 9 9 8 9"></polyline>
          </svg>
          <span>文档</span>
          <span class="file-count">24</span>
        </li>
        <li class="menu-item" :class="{ active: activeCategory === 'images' }" @click="handleCategoryClick('images')">
          <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
            <rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect>
            <circle cx="8.5" cy="8.5" r="1.5"></circle>
            <polyline points="21 15 16 10 5 21"></polyline>
          </svg>
          <span>图片</span>
          <span class="file-count">142</span>
        </li>
        <li class="menu-item" :class="{ active: activeCategory === 'videos' }" @click="handleCategoryClick('videos')">
          <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
            <polygon points="5 3 19 12 5 21 5 3"></polygon>
          </svg>
          <span>视频</span>
          <span class="file-count">35</span>
        </li>
        <li class="menu-item" :class="{ active: activeCategory === 'audio' }" @click="handleCategoryClick('audio')">
          <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
            <polygon points="11 5 6 9 2 9 2 15 6 15 11 19 11 5"></polygon>
            <path d="M19.07 4.93a10 10 0 0 1 0 14.14M15.54 8.46a5 5 0 0 1 0 7.07"></path>
          </svg>
          <span>音频</span>
          <span class="file-count">18</span>
        </li>
        <li class="menu-item" :class="{ active: activeCategory === 'archives' }" @click="handleCategoryClick('archives')">
          <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
            <rect x="2" y="3" width="20" height="14" rx="2" ry="2"></rect>
            <line x1="8" y1="21" x2="16" y2="21"></line>
            <line x1="12" y1="17" x2="12" y2="21"></line>
          </svg>
          <span>压缩包</span>
          <span class="file-count">9</span>
        </li>
      </ul>
    </div>
    
    <!-- 存储空间 -->
    <div class="storage-info">
      <div class="storage-header">
        <span>存储空间</span>
        <span>12.5GB / 50GB</span>
      </div>
      <div class="storage-bar">
        <div class="storage-used" style="width: 25%"></div>
      </div>
    </div>
  </aside>
</template>

<script>
export default {
  name: 'Sidebar',
  data() {
    return {
      activeMenu: 'myFiles', // 默认选中"我的文件"
      activeCategory: '' // 文件分类初始没有选中项
    }
  },
  methods: {
    handleMenuItemClick(menuName) {
      this.activeMenu = menuName
      this.activeCategory = '' // 清除分类选中状态
      // 这里可以添加实际的业务逻辑，例如加载对应的数据
      console.log(`点击了菜单: ${menuName}`)
    },
    handleCategoryClick(categoryName) {
      this.activeCategory = categoryName
      this.activeMenu = '' // 清除菜单选中状态
      // 这里可以添加实际的业务逻辑，例如加载对应分类的文件
      console.log(`点击了分类: ${categoryName}`)
    }
  }
}
</script>

<style scoped>
.sidebar {
  width: 240px;
  background-color: white;
  border-right: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-section {
  padding: 20px 0;
}

.section-title {
  font-size: 12px;
  font-weight: 600;
  color: #999;
  text-transform: uppercase;
  margin: 0 20px 12px;
}

.sidebar-menu {
  list-style: none;
  padding: 0;
  margin: 0;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  cursor: pointer;
  transition: background-color 0.2s;
  position: relative;
}

.menu-item:hover {
  background-color: #f5f5f5;
}

.menu-item.active {
  background-color: #f0f7ff;
  color: #0074D9;
  font-weight: 500;
}

.menu-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 3px;
  background-color: #0074D9;
}

.menu-item span:first-of-type {
  flex: 1;
}

.file-count {
  font-size: 12px;
  color: #999;
  background-color: #f5f5f5;
  padding: 2px 8px;
  border-radius: 10px;
}

.storage-info {
  padding: 20px;
  margin-top: auto;
  border-top: 1px solid #e0e0e0;
}

.storage-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 14px;
  color: #666;
}

.storage-bar {
  height: 8px;
  background-color: #f0f0f0;
  border-radius: 4px;
  overflow: hidden;
}

.storage-used {
  height: 100%;
  background-color: #0074D9;
  border-radius: 4px;
  transition: width 0.3s ease;
}
</style>